package pkg

import (
	"context"
	"github.com/qiniu/go-sdk/v7/storagev2/credentials"
	"github.com/qiniu/go-sdk/v7/storagev2/http_client"
	"github.com/qiniu/go-sdk/v7/storagev2/uploader"
	"mime/multipart"
)

func UpDateImg(file multipart.File, name string) error {

	accessKey := "FbaV5XkelC_NF1HdH5qsIf1nhEjwGQlTJ_a9Lm0p"
	secretKey := "il0QFAqpFuwmAtwzZwFVgeZEf7DIOZJB9aC8FMVi"
	mac := credentials.NewCredentials(accessKey, secretKey)

	bucket := "bobosha"
	key := "github-x.png"

	uploadManager := uploader.NewUploadManager(&uploader.UploadManagerOptions{
		Options: http_client.Options{
			Credentials: mac,
		},
	})
	err := uploadManager.UploadFile(context.Background(), name, &uploader.ObjectOptions{
		BucketName: bucket,
		ObjectName: &key,
		CustomVars: map[string]string{
			"name": "github logo",
		},
	}, nil)
	if err != nil {
		return err
	}

	return nil
}
